//
//  SevenViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/7.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class SevenViewController: UIViewController {

    fileprivate var _mainTableView:UITableView!;
    fileprivate let cellID = "seven_cell_id";
    fileprivate lazy var _mutArr:NSMutableArray = {
        var mutArr = NSMutableArray();
        mutArr.add("transiton");
        mutArr.add("转场动画push");
        mutArr.add("转场动画present");
        mutArr.add("颜色渐变Gradient")
        return mutArr;
    }();
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "动画"
        self.view.backgroundColor = .white;
        // Do any additional setup after loading the view.
        self.onCreateUIForNavigation();
        self.onCreateUIForView();
    }
    

    //TODO:UI
    fileprivate func onCreateUIForNavigation() {
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", style: .done, target: self, action: #selector(onBackActions))
    }
    
    fileprivate func onCreateUIForView() {
        _mainTableView = UITableView(frame: CGRect(x: 0, y: 0, width: screenMainSize.width, height: screenMainSize.height), style: .plain);
        _mainTableView.backgroundColor = .clear;
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.register(UITableViewCell.self, forCellReuseIdentifier: cellID);
        self.view.addSubview(_mainTableView);
    }
    
    //TODO:Actions
    @objc fileprivate func onBackActions() {
        self.navigationController?.dismiss(animated: true, completion: nil);
    }

}

extension SevenViewController:UITableViewDelegate {
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44;
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            let detailVC = SevenDetailViewController();
            self.navigationController?.pushViewController(detailVC, animated: true);
        case 1:
            let detailVC = SevenTransitionViewController();
            self.navigationController?.pushViewController(detailVC, animated: true);
        case 2:
            let detailVC = SevenPresentTransitionViewController();
            self.navigationController?.pushViewController(detailVC, animated: true);
        case 3:
            let detailVC = SevenGradientViewController();
            self.navigationController?.pushViewController(detailVC, animated: true);
        default:
            ""
        }
        
    }
}

extension SevenViewController:UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return _mutArr.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID)!;
        
        if _mutArr.count > indexPath.row {
            cell.textLabel?.text = (_mutArr[indexPath.row] as! String);
        }
        return cell
    }

}
